<div class="product-categories">

<?php 

foreach ($terms as $key => $val) {
?>
  <div class="product-sub-categories" id="sub-categories-<?php echo $key?>">
<?php
  foreach ($val as $tid => $term) {
    if ($term->depth == 0) {
      print "<div class='cat-item term-{$term->tid}'>" . l($term->name, "list/$term->tid") . "</div>";
      print "<div class='cat-item-body'>";
    }
    else {
      print "<div class='cat-item term-{$term->tid}'>" . l($term->name, "list/$term->tid"). "</div>";
    }
  }
  print "<div class='clear'></div></div>";
?>
  </div>
<?php } ?>
<div class="clear"></div>
</div>
